<%@ page import="org.apmap.base.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/tags/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tags/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tags/struts-logic.tld" prefix="logic" %>
<html>
<head>
    <title>ApMap.org</title>
    <link rel="shortcut icon" href="/img/cubisthome.png" type="image/x-icon" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <style type="text/css">
      @import url("http://www.google.com/uds/css/gsearch.css");
      @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
      }
    </style>
    <script type="text/javascript" src="/js/classes.js"></script>
    <script type="text/javascript" src="/js/utils.js"></script>
    <script type="text/javascript" src="/js/xmlparser.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript" src="/js/flats.js"></script>
    <script type="text/javascript" src="/js/offices.js"></script>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAEF-wjJ0SHv9-F6XnzkMuIxT-Qn7S59KW6bBPQmUQAwoFqN5NnRTdB3rjjEMg_4lloDzYaCibSzL8SQ" type="text/javascript"></script>
    <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0" type="text/javascript"></script>
    <script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script>

    <script type="text/javascript">

        var mgr = null;
        var globalmap = null;
        var userid = null;
        var ableSetFlat = false;
        var ableSetComerc = false;
        var centerLatLng = new GLatLng(59.94435107126614, 30.314369201660156); //Питер
        var lastLatLng = centerLatLng;
        var maxRadius = 30000;
        var cookiepath = 'spb';

        function initialize() {
            if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map_canvas"));
                globalmap = map;
                map.setCenter(centerLatLng, 13);
                //map.setCenter(new GLatLng(48.45, 35.03), 13); //Днепр

                GEvent.addListener(map, "moveend", function() {
                    var center = map.getCenter();
//                    var bound = map.getBounds();
//                    document.getElementById("message").innerHTML = center.toString()
//                            + '</br>' + bound.toString()
//                            + '<br/>' + centerLatLng.distanceFrom(center);
                    if(centerLatLng.distanceFrom(center) < maxRadius) {
                        screenMoveEnd(map);
                        lastLatLng = center;
                    } else {
                        map.setCenter(lastLatLng);
                    }

                });

                var myEventListener = GEvent.bind(map, "click", this, function(marker, latlng) {
                    if(userid != null && ableSetFlat) {
                        addHouse(latlng, map);
                    }
                    if(userid != null && ableSetComerc) {
                        addOffice(latlng, map);
                    }
                });
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());

                var localSearchOptions = {
                    resultList :G_GOOGLEBAR_RESULT_LIST_SUPPRESS,
                    onSearchCompleteCallback:function(){
                    if (this.gs.results && this.gs.results.length > 0) {
//                        this.gs.results[0].addressLookupResult) {

                        //если результат не в Питере - не показываем
//                        for (var i in this.gs.results) {
                        for (i = 0; i < this.gs.results.length; i++) {
                            var element = this.gs.results[i];
                            if(element.addressLookupResult && (element.country != 'RU' || element.city != 'город Санкт-Петербург')) {
                                this.gs.results = remove(this.gs.results, i);
                                i--;
//                                this.gs.results[i] = undefined;
//                                this.gs.results.pop();
                            }
                        }
                    }
                }};
                map.addControl(new google.maps.LocalSearch(localSearchOptions), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));

                screenMoveEnd(map);
            }
        }
    </script>
</head>
<body onload="initialize()" onunload="GUnload()">
<table width="100%" height="100%">
    <tr style="font-family:Arial;font-size:10px">
        <td height="1px" colspan="2" valign="top">

            <a href="/msk">Москва</a>
            <a href="/spb">Санкт-Петербург</a>
            <br/>

            <logic:present name="error" scope="session">
                <b><font color="red"><bean:write name="error" scope="session"/></font></b><br/>
                <%session.setAttribute("error", null);%>
            </logic:present>
            <logic:present name="user" scope="session">
                <%
                    User user = (User) session.getAttribute("user");
                %>
                <script type="text/javascript">
                    userid = <%=user.getId()%>;
                </script>

                <table>
                    <tr>
                        <td>
                            <b>Hello, <%=user.getProfile().get("name")%> !</b>
                        </td>
                        <td style="font-family:Arial;font-size:10px">
                            <a onclick="javascript:setFlat()"><img src="/img/cubisthome48.png"><br/>квартиры<br/>разместить объявление</a>
                        </td>
                        <td style="font-family:Arial;font-size:10px">
                            <a onclick="javascript:setComerc()"><img src="/img/comerc48.png"><br/>офисы<br/>разместить объявление</a>
                        </td>
                    </tr>
                </table>
            </logic:present>
            <logic:notPresent name="user" scope="session">
                <html:form action="/login">
                    login<html:text property="login"/>
                    password<html:password property="password"/>
                    <html:submit value="login"/>
                </html:form>
                <a href="/registration.jsp">registration</a><br/>
            </logic:notPresent>
        </td>
    </tr>

    <tr height="50%" valign="top" align="left">
        <td width="30%" height="200px">
            <div id="pointList" style="height: 100%;overflow-y:scroll;"></div>
        </td>
        <!--карта-->
        <td width="70%" rowspan="2"><div id="map_canvas" style="wPngServletidth: 100%; height: 100%"></div></td>
    </tr>
    <tr height="50%" width="30%" valign="bottom" align="left">
        <td>
            <div id="properties"></div>
        </td>
    </tr>
</table>
<div id="message"></div>

<%--google analytics--%>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-6896361-1");
pageTracker._trackPageview();
} catch(err) {}
</script>

</body>
</html>
